package com.sunday.volunteer.adapter;

import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.sunday.volunteer.R;
import com.sunday.volunteer.entity.Product;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by admin on 2017/1/10.
 */

public class ShopAdapter extends RecyclerViewAdapter{

    public ShopAdapter(List list, int layout) {
        super(list, layout);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(View itemView, int viewType) {
        return new ViewHolder(itemView);
    }
    public class ViewHolder extends MyViewHolder{
        @Bind(R.id.btn)
        TextView btn;
        @Bind(R.id.name)
        TextView name;
        @Bind(R.id.price)
        TextView price;
        @Bind(R.id.score)
        TextView score;
        @Bind(R.id.image_view)
        ImageView image;
        @Bind(R.id.num)
        TextView num;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this , itemView);
            btn.setOnClickListener(onClickListener);
            itemView.setOnClickListener(onClickListener);
        }

        @Override
        public void bind(MyViewHolder holder, Object object, int position) {
            Product item = (Product)object;
            btn.setTag(R.id.item ,item);
            itemView.setTag(R.id.item ,item);
            if(item == null){
                return;
            }

            setText(name , item.getName());
            setTextFormat(price ,"¥" ,String.valueOf(item.getMarketPrice()));
            price.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG| Paint.ANTI_ALIAS_FLAG);  // 设置中划线并加清晰
            setTextFormat(score , String.valueOf(item.getPrice()) ,"积分");
            setImage(image ,item.getImage() , 400 ,280);
            setText(num , String.format("限量%d%s" ,item.getStoreNumber() , "件"));
        }
    }
}
